<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>

<ui:composition template="/WEB-INF/layout.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui">

    <bean id="treinoController" class="controller.TreinoController">
        <property name="pagina" value="alterarTreino" />
    </bean>
    <ui:define name="content">
        <h:form id="form1">
            <p:panel id="panelTreino" header="Ficha de Treino">
                <p:messages autoUpdate="true"/>  
                <h:panelGrid columns="4" style="margin-bottom:10px; width: 100%" cellpadding="5">
                    <p:outputLabel for="nome" value="Nome:"/>
                    <p:inputText id="nome" value="#{treinoController.alunoSelecionado.nome}" disabled="true"/>
                    <p:outputLabel for="idade" value="Idade:"/>
                    <p:inputText id="idade" value="#{treinoController.idade}" disabled="true"/>
                    <p:outputLabel  for="objetivo" value="Objetivo:"/>
                    <p:selectOneMenu  value="#{treinoController.treino.objetivo}" id="objetivo" required="true" requiredMessage="Informe um objetivo">  
                        <f:selectItem itemLabel="Condicionamento Físico Geral" itemValue="Condicionamento Físico Geral"/>  
                        <f:selectItem itemLabel="Definição Muscular" itemValue="Definição Muscular"/>  
                        <f:selectItem itemLabel="Emagrecimento" itemValue="Emagrecimento"/>  
                        <f:selectItem itemLabel="Hipertrofia" itemValue="Hipertrofia"/>
                        <f:selectItem itemLabel="Resistência" itemValue="Resistência"/> 
                    </p:selectOneMenu>
                    <p:outputLabel for="frequencia" value="Frequência:"/>
                    <p:spinner id="frequencia" min="0" max="6" value="#{treinoController.treino.frequencia}" size="10" required="true"/>
                </h:panelGrid>

                <h:panelGrid columns="3" style="margin-bottom:10px" cellpadding="5">
                    <p:outputLabel for="obs" value="Observações:"/>
                    <p:spacer width="25" height="0" />
                    <p:inputText id="obs" value="#{treinoController.treino.observacao}" size="107" required="false"/>
                </h:panelGrid>

                <h:panelGrid columns="7" style="margin-bottom:10px" cellpadding="5">
                    <p:outputLabel for="preTreino" value="Pré-treino:"/>
                    <p:spacer width="37" height="0"/>
                    <p:selectOneMenu value="#{treinoController.idPreTreino}" id="preTreino" required="true">  
                        <f:selectItem itemLabel="Bicicleta" itemValue="1"/>  
                        <f:selectItem itemLabel="Corda" itemValue="2"/>  
                        <f:selectItem itemLabel="Pista" itemValue="3"/>
                    </p:selectOneMenu>
                    <p:spacer width="170" height="0"/>
                    <p:selectOneRadio value="#{treinoController.tipoPreTreino}">  
                        <f:selectItem itemLabel="Inicial" itemValue="Inicial"/>
                        <f:selectItem itemLabel="Final" itemValue="Final"/>    
                    </p:selectOneRadio>
                    <p:spacer width="230" height="0"/>
                    <p:commandButton id="addPreTreino" value="Adicionar" action="#{treinoController.adicionarPreTreino}" update="pretreinos"/>
                    <f:ajax render="pretreinos" event="click"/>
                </h:panelGrid> 

                <p:dataTable id="pretreinos" var="DTpretreino" style="width:100%;" 
                             value="#{treinoController.preTreinoDM}" editable="true">
                    <p:ajax event="rowEdit" listener="#{treinoController.onEdit}"/>                    
                    <p:column headerText="Nome">
                        <h:outputText value="#{DTpretreino.preTreino.nome}"/>                        
                    </p:column>

                    <p:column headerText="Tempo (min)" >
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{DTpretreino.tempo}"/>
                            </f:facet>
                            <f:facet name="input">
                                <p:inputText value="#{DTpretreino.tempo}"/>
                            </f:facet>
                        </p:cellEditor>
                    </p:column>

                    <p:column headerText="Intensidade (borg)">
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{DTpretreino.intensidade}"/>
                            </f:facet>
                            <f:facet name="input">
                                <p:inputText value="#{DTpretreino.intensidade}"/>
                            </f:facet>
                        </p:cellEditor>
                    </p:column>

                    <p:column  headerText="Tipo" >                     
                        <h:outputText value="#{DTpretreino.tipoPreTreino}"/>
                    </p:column>
                    <p:column style="width:6%">  
                        <p:rowEditor/>
                    </p:column> 
                </p:dataTable> <br/>

                <h:panelGrid columns="3" cellpadding="5">
                    <h:outputText value="Exercícios" style="font-size: x-large"/>
                    <p:spacer width="700" height="60"/>
                    <p:commandButton value="Adicionar Exercícios" onclick="PF('dlg').show();"/>
                </h:panelGrid>

                <p:dataTable id="DTexercicios" var="exercicioTreino"         
                             value="#{treinoController.exercicioTreinoDM}"
                             style="width:100%;"                             
                             rowKey="#{exercicioTreino.exercicio.idExercicio}"
                             selection="#{treinoController.exercicioTreinoSelecionado}" 
                             selectionMode="single">
                    <p:ajax event="rowSelect" listener="#{treinoController.onRowSelectExercicioTreino}"/>
                    <p:column headerText="Sequência">
                        #{exercicioTreino.sequencia} 
                    </p:column>

                    <p:column headerText="Grupo Muscular">
                        #{exercicioTreino.exercicio.grupoMuscular}
                    </p:column>

                    <p:column headerText="Exercício">
                        #{exercicioTreino.exercicio.nome}
                    </p:column> 

                    <p:column headerText="Série">
                        #{exercicioTreino.numeroSerie}
                    </p:column>  

                    <p:column  headerText="Repetições">
                        #{exercicioTreino.numeroRepeticoes}
                    </p:column>

                    <p:column headerText="Carga">
                        #{exercicioTreino.carga} 
                    </p:column>  

                    <p:column  headerText="Treino">  
                        #{exercicioTreino.tipoTreino}  
                    </p:column>

                    <p:column headerText="">
                        <p:commandButton icon="ui-icon-trash" actionListener="#{treinoController.excluirExercicioTreino}" update="DTexercicios"/>
                    </p:column>
                </p:dataTable>
                <p:spacer width="0" height="50"/>
                <p:commandButton value="Limpar" actionListener="#{treinoController.limparCampos}" update="form1"/>
                <p:spacer width="10" height="0"/>
                <p:commandButton value="Salvar" actionListener="#{treinoController.salvarTreino}" update="panelTreino"/>

                <p:dialog id="dialog" header="#{treinoController.cabecalhoMsg}" widgetVar="treinoDialog" resizable="false"  
                          showEffect="fade" hideEffect="explode">  
                    <h:panelGrid id="display" columns="2" cellpadding="4"> 
                        <h:outputText value="#{treinoController.mensagem}" />  
                    </h:panelGrid>  
                </p:dialog>              

                <p:growl id="growl" showDetail="true" life="3000"/>
                <p:dialog id="dialogExerc" header="Exercícios" widgetVar="dlg" resizable="false">  
                    <p:outputLabel value="Grupo Muscular:"/>
                    <p:spacer width="10" height="0"/>
                    <p:selectOneMenu value="#{treinoController.grupoMuscular}" required="true">
                        <f:selectItem itemLabel="--" itemValue="Vazio"/>
                        <f:selectItem itemLabel="Abdome" itemValue="Abdome"/>  
                        <f:selectItem itemLabel="Bíceps" itemValue="Bíceps"/>  
                        <f:selectItem itemLabel="Costas" itemValue="Costas"/>
                        <f:selectItem itemLabel="Coxa/Glúteo" itemValue="Coxa/Glúteo"/>
                        <f:selectItem itemLabel="Peito" itemValue="Peito"/>
                        <f:selectItem itemLabel="Perna" itemValue="Perna"/>
                        <f:selectItem itemLabel="Ombro" itemValue="Ombro"/>
                        <f:selectItem itemLabel="Tríceps" itemValue="Tríceps"/>
                        <f:ajax render="exercicios" event="valueChange" listener="#{treinoController.pesquisarExercicio}"/>
                    </p:selectOneMenu>
                    <p:spacer width="30" height="0"/>
                    <p:outputLabel value="Treino:"/>
                    <p:spacer width="10" height="0"/>
                    <p:selectOneMenu  value="#{treinoController.dadosExercicio.tipoTreino}" required="true">  
                        <f:selectItem itemLabel="A" itemValue="A"/>  
                        <f:selectItem itemLabel="B" itemValue="B"/>  
                        <f:selectItem itemLabel="C" itemValue="C"/>  
                        <f:selectItem itemLabel="D" itemValue="D"/>
                        <f:selectItem itemLabel="E" itemValue="E"/> 
                    </p:selectOneMenu><br/><br/>

                    <p:dataTable id="exercicios" var="exercicio"
                                 value="#{treinoController.exercicioDM}" 
                                 style="width:100%;" 
                                 rowKey="#{exercicio.idExercicio}"
                                 rows="5"
                                 selection="#{treinoController.exercicioSelecionado}" 
                                 selectionMode="single">
                        <p:ajax event="rowSelect" listener="#{treinoController.onRowSelect}"/>
                        <p:column headerText="Código">
                            #{exercicio.idExercicio}
                        </p:column>

                        <p:column headerText="Nome">  
                            #{exercicio.nome}  
                        </p:column>  

                        <p:column headerText="Grupo Muscular">  
                            #{exercicio.grupoMuscular}  
                        </p:column>
                    </p:dataTable> <br/>

                    <p:outputLabel for="serie" value="Serie:"/>
                    <p:spacer width="10" height="0"/>
                    <p:spinner id="serie" min="0" size="5" maxlength="0" value="#{treinoController.dadosExercicio.numeroSerie}" required="true"/>
                    <p:spacer width="20" height="0"/>
                    <p:outputLabel for="repeticoes" value="Repetições:"/>
                    <p:spacer width="10" height="0"/>
                    <p:spinner id="repeticoes" min="0" size="5" maxlength="0" value="#{treinoController.dadosExercicio.numeroRepeticoes}" required="true"/>
                    <p:spacer width="20" height="0"/>
                    <p:outputLabel for="carga" value="Carga:"/>
                    <p:spacer width="10" height="0"/>
                    <p:spinner id="carga" min="0" size="5" maxlength="0" value="#{treinoController.dadosExercicio.carga}" required="true"/>
                    <p:spacer width="20" height="0"/>
                    <p:commandButton value="OK" actionListener="#{treinoController.salvarDados}" update="repeticoes, serie, carga, dialog"/> <br/>
                    <p:spacer width="0" height="50"/>
                    <p:commandButton value="Cancelar" oncomplete="dlg.hide()" actionListener="#{treinoController.cancelarDados}"/>
                    <p:spacer width="10" height="0"/>
                    <p:commandButton value="Incluir" actionListener="#{treinoController.incluirDados}" oncomplete="dlg.hide()"
                                     update="DTexercicios"/>
                    <f:ajax render="exercicios" event="close"/>
                </p:dialog>  
            </p:panel>
        </h:form>
    </ui:define>
</ui:composition>

